<template>
    <main id="main" class="site-main karma-blog-page" role="main">
        <div class="container">
            <div class="row">
                <div class="karma-blog-content col-sm-9">
                    <article class="blog-grid margin-b-30 athena-blog-post reveal">
                        <div class="blog-grid-content">
                            <h3 class="blog-grid-title-lg">激活注册</h3>

                            <div class="login-content">
                                <div class="row">
                                    <div class="col-md-6 col-xs-12">
                                        <form class="margin-bottom-0" id="sendForm">
                                            <input name="code" type="hidden" value="">
                                            <div class="form-group m-b-15">
                                                <input name="cipher" v-model="cipher" type="hidden" class="form-control"
                                                       readonly/>
                                                <input name="email" v-model="email" type="text" class="form-control"
                                                       placeholder="账号" readonly/>
                                            </div>
                                            <div class="form-group m-b-15">
                                                <input type="text" name="name" v-model="name" class="form-control"
                                                       placeholder="昵称"/>
                                            </div>
                                            <div class="form-group m-b-15">
                                                <input type="password" name="password" v-model="password"
                                                       class="form-control"
                                                       placeholder="密码"/>
                                            </div>
                                            <div class="form-group m-b-15">
                                                <input type="text" name="code" v-model="code" class="form-control"
                                                       placeholder="验证码"/>
                                            </div>
                                            <div class="login-buttons">
                                                <a id="doReg" @click="active"
                                                   class="btn btn-info btn-block btn-lg">激活</a>
                                            </div>
                                            <div class="form-group m-b-15">
                                                <p id="showTip" class="input-lg text-center text-danger"></p>
                                            </div>
                                            <hr/>
                                        </form>
                                    </div>
                                    <div class="col-md-6 col-xs-12 text-center">
                                        <img src="https://yanghaha.vip/front/img/weixin.png">
                                    </div>
                                </div>
                            </div>

                        </div>
                    </article>
                </div>
            </div>

        </div>

    </main>
</template>

<script>
    import BaseService from "@/services/BaseService";

    const BaseServiceApi = new BaseService();
    export default {
        name: "Activate",
        data: function () {
            return {
                cipher: this.$route.params.cipher,
                email: this.$route.params.email,
                name: "",
                password: "",
                code: ""
            };
        },
        methods: {
            active: function () {
                let data = {
                    cipher: this.cipher,
                    email: this.email,
                    name: this.name,
                    password: this.password,
                    code: this.code,
                };
                BaseServiceApi.postApi("/api/v1/active", data).then(res => {
                    if (res.data.code === 200) {
                        BaseServiceApi.setStorage("token", res.data.data.token);
                        window.location.href = "/";
                    } else {
                        this.msg = res.data.msg;
                        this.code = "";
                    }
                });
            }
        }
    }
</script>

<style scoped>

</style>
